package cqrtplm.listener;


import cn.hutool.extra.spring.SpringUtil;
import com.hustcad.plm.pdm.workflow.annotion.CustomListener;
import com.hustcad.plm.pdm.workflow.annotion.CustomListenerField;
import com.hustcad.plm.pdm.workflow.model.constant.ProcessConstant;
import cqrtplm.service.FlowControlService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.impl.el.FixedValue;

import java.math.BigInteger;

@Slf4j
@CustomListener(category = "润通", description = "并行节点检查")
public class RTParallelNodeCheckListener implements ExecutionListener {

    @CustomListenerField(description = "判断并行节点ID",defaultValue ="",required = true)
    private FixedValue parma;

    @Override
    public void notify(DelegateExecution execution) {
        long start = System.currentTimeMillis();
        String workFlowContainerId = execution.getProcessInstanceBusinessKey();
        log.info("----------润通----并行节点检查------开始------workFlowContainerId:{}----->>>",
                 workFlowContainerId);
        if (StringUtils.isBlank(workFlowContainerId)) {
            workFlowContainerId = execution.getVariable(ProcessConstant.WORK_FLOW_CONTAINER_ID).toString();
        }
        String finalWorkFlowContainerId = workFlowContainerId;
        FlowControlService flowControlService = SpringUtil.getBean(FlowControlService.class);
//        flowControlService.parallelNodeCheckListener(new BigInteger(finalWorkFlowContainerId),
//                                                     parma.getExpressionText());

        log.info("----------润通----并行节点检查,耗时：{}---->>>", System.currentTimeMillis() - start);
    }
}
